package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.Permit;

/**
 * 
 * @author 
 *
 */
@DAO
public interface PermitDAO{
	
	@SQL("SELECT orderNo,code,returnCode,areaName,schoolName,address,name,identityCard,parentName,parentPhone,teacher,area,school,grade,status FROM GameOrder WHERE deleteFlag=1 AND gameId=:1 LIMIT :2,:3 ")
    List<Map> queryGameOrderByGameId(int gameId,int start,int length);
	
	@SQL("SELECT count(*) FROM GameOrder WHERE deleteFlag=1 AND gameId=:1 ")
    int queryGameOrderSize(int gameId);
	
	@SQL("SELECT areaName,schoolName,address,code,pwdShow,returnCode,status FROM Permit WHERE deleteFlag=1 AND gameId=:1 LIMIT :2,:3 ")
    List<Map> queryByGameId(int gameId,int start,int length);
	
	@SQL("SELECT count(*) FROM Permit WHERE deleteFlag=1 AND gameId=:1 ")
    int querySize(int gameId);
	
	@SQL("SELECT * FROM Permit WHERE deleteFlag=1 AND gameId=:t.gameId AND status=:t.status #if(:t.code!=''){ AND code LIKE '%##(:t.code)%' } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<Permit> query(@SQLParam("t") Permit permit);
	
	@SQL("SELECT count(*) FROM Permit WHERE deleteFlag=1 AND gameId=:t.gameId AND status=:t.status #if(:t.code!=''){ AND code LIKE '%##(:t.code)%' } ")
    int querysize(@SQLParam("t") Permit permit);
	
	@SQL("SELECT * FROM Permit WHERE code=:1 and gameId=:2 ")
    Permit queryByCode(String code,int gameId);
    
    @SQL("SELECT * FROM Permit WHERE id=:1")
    Permit queryById(int id);
    
    @SQL("INSERT INTO Permit (gameId,areaId,areaName,schoolId,schoolName,address,code,returnCode,pwd,pwdShow,status,deleteFlag,createAt,createUser,updateAt,updateUser) VALUES (:t.gameId,:t.areaId,:t.areaName,:t.schoolId,:t.schoolName,:t.address,:t.code,:t.returnCode,:t.pwd,:t.pwdShow,:t.status,1,now(),:t.createUser,now(),:t.updateUser)")
    void create(@SQLParam("t") Permit permit);
	
	@SQL("UPDATE Permit SET gameId=:t.gameId,areaId=:t.areaId,schoolId=:t.schoolId,code=:t.code,returnCode=:t.returnCode,pwd=:t.pwd,pwdShow=:t.pwdShow,status=:t.status,updateAt=now(),updateUser=:t.updateUser WHERE id=:t.id")
    void update(@SQLParam("t") Permit permit);
	
	@SQL("DELETE FROM Permit WHERE gameId=:1")
    void removeByGId(int gameId);
    
    @SQL("UPDATE Permit SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("select id as permitId,areaName,schoolName,address,returnCode from Permit where deleteFlag=1 and gameId=:1 and code=:2 and pwd=:3 and status=1")
	List<Map> validate(int gameId, String code, String pwd);
    
    @SQL("update Permit set status=:2,updateUser=:3,updateAt=NOW() where id=:1")
    void changeStatusById(int id, int status, String account);

    @SQL("select id as permitId,gameId,areaName,schoolName,address,code,returnCode from Permit where deleteFlag=1 and id=:1 and status=1")
	List<Map> getValidatePermitById(int permitId);
}
